//
//  ReadLoginData.m
//  EasyToTesco
//
//  Created by mc on 16/3/14.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "ReadLoginData.h"

@implementation ReadLoginData


+ (void)removeDataToLocal:(NSString *)plistPath {
    NSString *fileName = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:plistPath];
    
    NSFileManager *fm = [NSFileManager defaultManager];
    
    if ([fm fileExistsAtPath:fileName]) {
        
        NSError *error = nil;
        [fm removeItemAtPath:fileName error:&error];
    }
    
}

+(void)saveAddressDataToLocal:(NSDictionary *)userAddressDict {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"addressData.plist"];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    
    [userAddressDict writeToFile:filename atomically:YES];
    
}

+ (NSMutableDictionary *)readAddressData {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    
    //    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:@"addressData.plist"];
    //读文件
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return dic;
}

+ (void)saveShopDataToLocal:(NSArray *)shopDataArr {
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    NSLog(@"%@", shopDataArr);
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"shopData.plist"];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    BOOL a = [shopDataArr writeToFile:filename atomically:YES];
    
    if (a) {
        NSLog(@"写入成功");
    } else {
        NSLog(@"写入失败");
    }
    
}

+ (NSMutableArray *)readShopArr {
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    
    //    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:@"shopData.plist"];
    //读文件
    NSMutableArray *readShopArr = [NSMutableArray arrayWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return readShopArr;
}

+ (void)savelogindataToLocal:(NSDictionary *)userDataDict{
    
    
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"loginData.plist"];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    
    [userDataDict writeToFile:filename atomically:YES];
    
}

+ (void)savelogindataToLocal:(NSDictionary *)userDataDict AndPlistPath:(NSString *) string {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:string];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    
    [userDataDict writeToFile:filename atomically:YES];
}
+ (void)saveZhuanPanToLocal:(NSArray *)shopDataArr {
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    
    NSString *filename=[path stringByAppendingPathComponent:@"zhuanpan.plist"];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    BOOL a = [shopDataArr writeToFile:filename atomically:YES];
    
    if (a) {
        NSLog(@"写入成功");
    } else {
        NSLog(@"写入失败");
    }
    
}

+ (NSMutableArray *)readZhuanPanArr {
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    
    //    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:@"zhuanpan.plist"];
    //读文件
    NSMutableArray *readShopArr = [NSMutableArray arrayWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return readShopArr;
}
+ (NSMutableDictionary *)readLoginData {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    
    //    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:@"loginData.plist"];
    //读文件
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return dic;
}

+ (NSMutableDictionary *)readLoginDataWithPathPlistString:(NSString *)plistPath {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    
    //    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:plistPath];
    //读文件
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return dic;
}

@end
